package com.ze.sys.config;

import com.ze.threadpool.config.CustomNameThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolConfig {

    @Bean(name = "mailThreadPool")
    public ThreadPoolExecutor getMailThreadPool() {
        // 创建自定义的线程工厂(用于自定义线程名)
        CustomNameThreadFactory mailThreadFactory = new CustomNameThreadFactory("mail");
        // 创建线程池
        return new ThreadPoolExecutor(
                10,
                10,
                5,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                mailThreadFactory,
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
    }
}